
(function(){
    var t;
    function size(animate){
        if (animate == undefined){
            animate = false;
        }
        clearTimeout(t);
        t = setTimeout(function(){
            $("canvas").each(function(i,el){
                $(el).attr({
                    "width":$(el).parent().width(),
                    "height":$(el).parent().outerHeight()
                });
            });
            redraw(animate);
            var m = 0;
            $(".chartJS").height("");
            $(".chartJS").each(function(i,el){ m = Math.max(m,$(el).height()); });
            $(".chartJS").height(m);
        }, 30);
    }
    $(window).on('resize', function(){ size(false); });


    function redraw(animation){
        var options = {};
        if (!animation){
            options.animation = false;
        } else {
            options.animation = true;
        }
        options.scaleOverlay = true;


        var barChartData = {
            labels : ["微博平台","短信平台","邮件平台","客服平台"],
            datasets : [
                {
                    fillColor : "#CDCDB4",
                    strokeColor : "#CDCDB4",
                    data : [20,14,32,19]
                },
                {
                    fillColor : "#868BB8",
                    strokeColor : "#868BB8",
                    data : [38,80,50,29]
                }
            ]

        };

        var myLine = new Chart(document.getElementById("bar-chart-js").getContext("2d")).Bar(barChartData);


        var Linedata = {
            labels : ["微博平台","短信平台","邮件平台","客服平台"],
            datasets : [
                {
                    fillColor : "#4EC9B4",
                    strokeColor : "#4EC9B4",
                    pointColor : "#4EC9B4",
                    pointStrokeColor : "#fff",
                    data : [220,119,190,281]
                },
                {
                    fillColor : "#81CDEA",
                    strokeColor : "#81CDEA",
                    pointColor : "#81CDEA",
                    pointStrokeColor : "#fff",
                    data : [165,80,120,181]
                },
                {
                    fillColor : "#ffea80",
                    strokeColor : "#ffea80",
                    pointColor : "#ffea80",
                    pointStrokeColor : "#fff",
                    data : [28,12,40,60]
                }

            ]
        };
        var myLineChart = new Chart(document.getElementById("line-chart-js").getContext("2d")).Line(Linedata);
    }


    size(true);

}());
